package labelsystem.Service.Implements;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/3/26 20:18
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import labelsystem.Mapper.doctorMapper;
import labelsystem.Mapper.orderMapper;
import labelsystem.Mapper.textMapper;
import labelsystem.Mapper.videoMapper;
import labelsystem.Pojo.Doctor;
import labelsystem.Pojo.Order;
import labelsystem.Pojo.Text;
import labelsystem.Pojo.Video;
import labelsystem.Service.doctorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *description: TODO
 *@author MCG
 *@date 2023/3/26 20:18
 *@Version 1.0
 */
@Service
public class doctorServiceImplement implements doctorService {
    @Resource
    doctorMapper doctorMapper;
    @Resource
    videoMapper videoMapper;
    @Resource
    textMapper textMapper;
    @Resource
    orderMapper orderMapper;
    @Override
    public boolean loginInByPassword(String telephone, String password) {
        QueryWrapper<Doctor> doctorQueryWrapper=new QueryWrapper<>();
        doctorQueryWrapper.eq("phone",Long.parseLong(telephone));
        return password.equals(doctorMapper.selectOne(doctorQueryWrapper));
    }

    @Override
    public boolean loginByVerifyCode(String input, String code) {
        return input.equals(code);
    }

    @Override
    public Doctor registerDoctor(String name, String gender, String grade, String workplace, String specify, Long phone, String url, String password, Float price, String introduction, String veUrl, Float rating) {
        Doctor doctor=new Doctor();
        doctor.setName(name);
        doctor.setWorkplace(workplace);
        doctor.setSpecify(specify);
        doctor.setPrice(price);
        doctor.setPhotoUrl(url);
        doctor.setPhone(phone);
        doctor.setGender(gender);
        doctor.setPassword(password);
        doctor.setCertificate(veUrl);
        doctor.setGrade(grade);
        doctor.setIntroduction(introduction);
        doctor.setRating(rating);
        doctorMapper.insert(doctor);
        return doctor;
    }

    @Override
    public Doctor queryPersonalInfo(Long doctorId) {
        return doctorMapper.selectById(doctorId);
    }

    @Override
    public boolean saveText(Long doctorId, String url) {
        Text text=new Text();
        text.setOffId(doctorId);
        text.setType("0");
        text.setUrl(url);
        return 1==textMapper.insert(text);
    }

    @Override
    public boolean saveVideo(Long doctorId, String url) {
        Video video=new Video();
        video.setOffId(doctorId);
        video.setCreateType("0");
        return 1==videoMapper.insert(video);
    }

    @Override
    public List<Order> selectOrders(Long doctorId) {
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",doctorId);
        queryWrapper.eq("type","0");
        return orderMapper.selectList(queryWrapper);
    }

    @Override
    public List<Text> selectTexts(Long doctorId) {
        QueryWrapper<Text> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",doctorId).eq("create_type","0");
        return textMapper.selectList(queryWrapper);
    }

    @Override
    public List<Video> selectRadio(Long doctorId) {
        QueryWrapper<Video> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("offer_id",doctorId).eq("create_type","0");
        return videoMapper.selectList(queryWrapper);
    }

    @Override
    public Doctor queryInfoByTel(Long phone) {
        QueryWrapper<Doctor> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        return doctorMapper.selectOne(queryWrapper);
    }

    @Override
    public Doctor updateInfo(Doctor doctor) {
        doctorMapper.updateById(doctor);
        return doctor;
    }
}
